import { defineStore } from "pinia"
import axios from "axios"
import { nanoid } from "nanoid"

// export const useTalkStore = defineStore('talk',{
//     actions:{
//          async getATalk(){
//             let {data:{content}} =  await axios.get('https://api.uomg.com/api/rand.qinghua?format=json')
// 			console.log(content);
// 			let obj = {id:nanoid(),title:content}
// 			this.talkList.unshift(obj)
//         }
//     },
//     state() {
//         return {
//             talkList:JSON.parse(localStorage.getItem('talkList') as string ) || []
//         }
//     },
// })
import { reactive } from "vue"
export const useTalkStore = defineStore('talk',()=>{
    //相当于state
    const talkList =  reactive([
        JSON.parse(localStorage.getItem('talkList') as string ) || []
    ])

    //相当于action
    async function getATalk(){
        let {data:{content}} =  await axios.get('https://api.uomg.com/api/rand.qinghua?format=json')
        console.log(content);
        let obj = {id:nanoid(),title:content}
        talkList.unshift(obj)
    }

    return {talkList,getATalk}
})